]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ibusManager: Preload all ibus input sources in user configuration
authorTakao Fujiwara <tfujiwar@redhat.com>
Mon, 10 Nov 2014 10:09:08 +0000 (19:09 +0900)
committerRui Matos <tiagomatos@gmail.com>
Wed, 12 Nov 2014 20:07:19 +0000 (21:07 +0100)
Normally users switch xkb input sources and ibus input sources.
But currently the first input source only is running. It's also good
to preload all ibus engines in the logging session so that users switch
input sources quickly without the launching time of input sources.

The following is the ibus change:
https://github.com/ibus/ibus/commit/cff35929a9

https://bugzilla.gnome.org/show_bug.cgi?id=695428

js/misc/ibusManager.js
js/ui/status/keyboard.js

index 9571e0b44c259b8e299aa1e1d40d42c83aa6257e..06d808d3f5d62135891ea33b6198b410c1f8f139 100644 (file)
@@ -1,13 +1,14 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
 try {
     var IBus = imports.gi.IBus;
-    if (!('new_async' in IBus.Bus))
-        throw "IBus version is too old";
+    _checkIBusVersion();
     const IBusCandidatePopup = imports.ui.ibusCandidatePopup;
 } catch (e) {
     var IBus = null;
@@ -16,6 +17,22 @@ try {
 
 let _ibusManager = null;
 
+function _checkIBusVersion() {
+    var requiredMajor = 1;
+    var requiredMinor = 5;
+    var requiredMicro = 2;
+
+    if ((IBus.MAJOR_VERSION > requiredMajor) ||
+        (IBus.MAJOR_VERSION == requiredMajor && IBus.MINOR_VERSION > requiredMinor) ||
+        (IBus.MAJOR_VERSION == requiredMajor && IBus.MINOR_VERSION == requiredMinor &&
+         IBus.MICRO_VERSION >= requiredMicro))
+        return;
+
+    throw "Found IBus version %d.%d.%d but required is %d.%d.%d".
+        format(IBus.MAJOR_VERSION, IBus.MINOR_VERSION, IBus.MINOR_VERSION,
+               requiredMajor, requiredMinor, requiredMicro);
+}
+
 function getIBusManager() {
     if (_ibusManager == null)
         _ibusManager = new IBusManager();
@@ -28,6 +45,7 @@ const IBusManager = new Lang.Class({
     // This is the longest we'll keep the keyboard frozen until an input
     // source is active.
     _MAX_INPUT_SOURCE_ACTIVATION_TIME: 4000, // ms
+    _PRELOAD_ENGINES_DELAY_TIME: 30, // sec
 
     _init: function() {
         if (!IBus)
@@ -42,6 +60,7 @@ const IBusManager = new Lang.Class({
         this._ready = false;
         this._registerPropertiesId = 0;
         this._currentEngineName = null;
+        this._preloadEnginesId = 0;
 
         this._ibus = IBus.Bus.new_async();
         this._ibus.connect('connected', Lang.bind(this, this._onConnected));
@@ -176,5 +195,27 @@ const IBusManager = new Lang.Class({
         this._ibus.set_global_engine_async(id, this._MAX_INPUT_SOURCE_ACTIVATION_TIME,
                                            null, callback);
     },
+
+    preloadEngines: function(ids) {
+        if (!IBus || !this._ibus || ids.length == 0)
+            return;
+
+        if (this._preloadEnginesId != 0) {
+            Mainloop.source_remove(this._preloadEnginesId);
+            this._preloadEnginesId = 0;
+        }
+
+        this._preloadEnginesId =
+            Mainloop.timeout_add_seconds(this._PRELOAD_ENGINES_DELAY_TIME,
+                                         Lang.bind(this, function() {
+                                             this._ibus.preload_engines_async(
+                                                 ids,
+                                                 -1,
+                                                 null,
+                                                 null);
+                                             this._preloadEnginesId = 0;
+                                             return GLib.SOURCE_REMOVE;
+                                         }));
+    },
 });
 Signals.addSignalMethods(IBusManager.prototype);
index 8cb8cc913ca7c15592952613d6ba3249ce04f174..4ae8ba1bd4413cbf1d17624b542ae5d3a0f728ca 100644 (file)
@@ -381,6 +381,10 @@ const InputSourceManager = new Lang.Class({
 
         if (this._mruSources.length > 0)
             this._mruSources[0].activate();
+
+        // All ibus engines are preloaded here to reduce the launching time
+        // when users switch the input sources.
+        this._ibusManager.preloadEngines(Object.keys(this._ibusSources));
     },
 
     _makeEngineShortName: function(engineDesc) {